﻿
using System;
using System.Text;
using sharpxbot.Core.Security.Traffic.Counters;
namespace sharpxbot.Core.Security.Traffic.Reports
{
    public class HourReport : ITrafficReport
    {
        #region Properties

        public DateTime Date { get; set; }

        public long IncomingBytes { get; set; }

        public long OutgoingBytes { get; set; }

        #endregion

        public HourReport(HourCounters incoming, HourCounters outgoing)
        {
            if (incoming == null || outgoing == null)
                throw new NullReferenceException("Illegal null-reference parameters. HourReport ctor");

            if (incoming.Hour != outgoing.Hour)
                throw new ArgumentException("Inconsistent hour in counters");

            DateTime now = DateTime.Now.Date;
            Date = now.AddHours(incoming.Hour);

            IncomingBytes = incoming.CalculateTotal();
            OutgoingBytes = outgoing.CalculateTotal();
        }

        #region ITrafficReport Members

        public string GetText()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(String.Format("Hourly report for {0}", Date));
            sb.AppendLine(String.Format("Incoming bytes: [{0}]", IncomingBytes));
            sb.AppendLine(String.Format("Outgoing bytes: [{0}]", OutgoingBytes));
            return sb.ToString();
        }

        #endregion
    }
}
